package cn.wolfcode.trip.app.controller;


import cn.wolfcode.trip.base.domain.News;
import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.query.NewsQueryObject;
import cn.wolfcode.trip.base.query.StrategyQuery;
import cn.wolfcode.trip.base.service.ICollectService;
import cn.wolfcode.trip.base.service.INewsService;
import cn.wolfcode.trip.base.service.ITravelService;
import cn.wolfcode.trip.base.util.JSONResult;
import cn.wolfcode.trip.base.util.UserContext;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/news")
public class NewsController {

    @Autowired
    private INewsService newsService;
    @Autowired
    private ITravelService travelService;
    @Autowired
    private ICollectService collectService;

    /**
     * 根据状态查询日报 黄子茵
     * 包含内容
     * @return
     */
    @GetMapping("/content")
    public PageInfo query(NewsQueryObject qo){
        qo.setOrderBy("n.releaseTime desc");
        PageInfo<News> query = newsService.query(qo);
        return query;
    }

    //获取单篇日报内容  黄子茵
    @GetMapping("/{id}")
    public Object selectByNewsId(@PathVariable Long id){
        return  newsService.selectContentByNewsId(id);
    }


    /** qiuyanquan
     * 判断用户是否收藏该文章
     * @param travelId
     * @param userId
     * @return
     */
    @GetMapping("/collectionCount")
    public  Integer getCollectionById( Long travelId, Long userId,int type){
        return travelService.getCollectionById(travelId,userId,type);
    }


    /** qiuyanquan
     * 收藏日报
     * @param travelId
     * @param userId
     * @param type
     * @return
     */
    @PostMapping("/collection")
    public JSONResult save(Long travelId,Long userId,int type) {
        travelService.save(travelId,userId,type);
        return new JSONResult();
    }

    /** qiuyanquan
     * 取消收藏日报
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public JSONResult delete(@PathVariable Long id) {
        Long userId = UserContext.getCurrentUser().getId();
        travelService.delete(id,userId,3);
        return new JSONResult();
    }

    @GetMapping("/nums")
    public int getNums(Long newsId,int type){
        return collectService.getNums(newsId,type);
    }

    @GetMapping("/praiseNum")
    public int getPraiseNum(Long newsId,int type){
        return collectService.getPraiseNum(newsId,type);
    }

}
